import axios from 'axios'
import { Loading, Message } from 'element-ui';
// loading变量
const service = axios.create({
    baseURL: process.env.VUE_APP_IOTBACK_API,
    timeout: 10000 // request timeout
})
// service._requestCount = 0; // 累加请求次数
// service._requestTimeIdList = [];
service.interceptors.request.use(
    config => {
        config.headers['Content-Type'] = 'application/json'
        return config
    },
    error => {
        Message.error({
            message: error
        })
        return Promise.reject(error)
    }
)
service.interceptors.response.use(
    response => {
        const res = response
        // if the custom code is not 20000, it is judged as an error.
        if (res.status !== 200) {
            return Promise.reject(new Error(res.message || 'Error'))
        } else {
            return res
        }
    },
    error => {

        Message.error({
            message: error
        })
        console.log('err', error) // for debug
        return Promise.reject(error)
    }
)
export default service
